package code

import (
	"github.com/gin-gonic/gin"
	"time"
)

type Response struct {
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data,omitempty"`
	Timestamp int64       `json:"timestamp"`
}

// Respond 统一响应方法
func Respond(c *gin.Context, status Code, data interface{}) {
	begin := time.Now()

	resp := Response{
		Code:      status.Code,
		Message:   status.Message,
		Data:      data,
		Timestamp: begin.Unix(),
	}

	c.JSON(status.HTTPStatus, resp)

	c.Abort()
}
